

 $(document).ready(function() {
 	var cookie=  $.AMUI.utils.cookie;
 	var sessionId=(cookie.get("sessionId")==null)?"":cookie.get("sessionId");
 	/*if(null == sessionId || "undefined" == sessionId || "" == sessionId){
 		
 	}else{*/
 		$.getJSON("json/locat.json", function(
					data) {
				var locat = data["url"];
				$.ajax(locat + "/appClient/to_appAddDirver",
						{
							type : "POST",
							xhrFields : {
								withCredentials : true,
								useDefaultXhrHeader : false
							},
							crossDomain : true,
							success : function(data, status, xhr) {
								document.getElementById('drivername').value = "";
								document.getElementById('driverphone').value = "";
								document.getElementById('tracknumber').value = "";
								document.getElementById('idnumber').value = "";
								document.getElementById("token").value=data["token"];
							},
							error : function(data) {
								var time = setTimeout(function() {
									//关闭
									$(window).loading({
										action : "close",
										id : id
									});
								}, 100);
								swal("", "服务异常！", "error");
								window.location.href ="login.html";
							}
						});
			});
 	//}
	
 	
 	
 });

function idyanzheng(id){
	if(id.length<16){
		swal("身份证号位数不对，请重新输入");
		$("#idnumber").css({
			"color" : "red",
		});
		document.getElementById("idnumber3").value="error";
	}else{
		document.getElementById("idnumber3").value="success";
		$("#idnumber").css({
			"color" : "black",
		});
	}
}


//保存司机
function save() {
	var cookie = $.AMUI.utils.cookie;
	var companyid = (cookie.get("companyid") == null) ? "" : cookie
			.get("companyid");
	var drivername = $("#drivername").val();
	var driverphone = $("#driverphone").val();
	var tracknumber = $("#tracknumber").val();
	var idnumber=$("#idnumber").val();
	var idnumber3=$("#idnumber3").val();
	if (drivername == "" || driverphone == "" || tracknumber == "") {
		swal("填写有误，请重新填写");
		$("#doc-vld-msg").submit();
		return false;
	} else {
		if (driverphone.length != 11 || tracknumber.length != 7||idnumber3=="error") {
			$("#doc-vld-msg").submit();
			return false;
		} else {
			var token = $("#token").val();
			var id = "body-loading";
			$(window).loading({
				action : "open",
				id : id,
				font : 40
			});
			$.getJSON("json/locat.json", function(
					data) {
				var locat = data["url"];
				var factoryid = data["factoryid"];
				$.ajax(locat + "/clientUser/saveDriver",
						{
							type : "POST",
							xhrFields : {
								withCredentials : true,
								useDefaultXhrHeader : false
							},
							data : {
								drivername : drivername,
								driverphone : driverphone,
								tracknumber : tracknumber,
								idnumber:idnumber,
								token : token
							},
							crossDomain : true,
							success : function(data, status, xhr) {
								var time = setTimeout(function() {
									//关闭
									$(window).loading({
										action : "close",
										id : id
									});
								}, 100);
								if ("success" == data["msg"]) {
									swal("新增成功", "", "success");
									window.location.href = window.location.href="tjsj.html";
								} else if ("repeat" == data["msg"]) {
									swal("已提交,请勿重复提交");
									window.location.href = window.location.href="tjsj.html";
								}
							},
							error : function(data) {
								var time = setTimeout(function() {
									//关闭
									$(window).loading({
										action : "close",
										id : id
									});
								}, 100);
								swal("", "服务异常！", "error");
								window.location.href = locat
										+ "clientUser/tologin";
							}
						});
			});

		}

	}

}

/*function save(){
	var cookie=  $.AMUI.utils.cookie;
 	var sessionId=(cookie.get("sessionId")==null)?"":cookie.get("sessionId");
	var drivername = $("#drivername").val();
	var driverphone = $("#driverphone").val();
	var tracknumber = $("#tracknumber").val();
	if(drivername==""||driverphone==""||tracknumber==""){
			$("#doc-vld-msg").submit();
			return false;
	}else{
		if(driverphone.length!=11||tracknumber.length!=7){
			$("#doc-vld-msg").submit();
			return false;
		}else{
			var id = "body-loading";
  	$(window).loading({action:"open",id:id,font:40}); 
	$.getJSON ("json/locat.json", function (data) {
			var  locat=data["url"];
			var factoryid=data["factoryid"];
	        $.ajax(locat+"/clientUser/saveDriver?sessionId="+sessionId, {
	            type: "POST",
	            xhrFields: {
	                withCredentials: true,
	                useDefaultXhrHeader: false
	            },
	            data: {
	                drivername: drivername,
	                driverphone: driverphone,
	                tracknumber: tracknumber
	            },
	            crossDomain: true,
	            success: function(data, status, xhr) {
	            		var time = setTimeout(function(){
			   				//关闭
			   				$(window).loading({action:"close",id:id});
			   			},100);
						if("success" == data["msg"]){
								swal("Good","新增成功","success");
								window.location.href="tjsj.html";
						}
	            },
	            error:function(data){
	            	var time = setTimeout(function(){
			   				//关闭
			   				$(window).loading({action:"close",id:id});
			   			},100);
	            	swal("","服务异常！","error");
	            	window.location.href=login.html;
	            }
	        });
    });  
		}
		
	}
	



}
*/